"""
-----------------------------
   File Name:loginapi
   Author:cwei
   date: 2023/7/28-9:47
-----------------------------
"""
import requests


class IHRMAPI:
    # 登录接口
    @classmethod
    def login_api(cls, ihrm_body):
        ihrm_login_url = 'http://ihrm2-test.itheima.net/api/sys/login'
        ihrm_header = {"Content-Type": "application/json"}

        resp = requests.post(url=ihrm_login_url, headers=ihrm_header, json=ihrm_body)

        return resp

        pass

    @classmethod
    def get_code_api(cls, session):
        code_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify"
        session.get(url=code_url)

    @classmethod
    def tpshop_login_api(cls, session, login_body):
        login_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        login_header = {"Content-Type": "application/x-www-form-urlencoded"}

        login_res = session.post(url=login_url, headers=login_header, data=login_body)
        return login_res

    # 添加员工接口
    @classmethod
    def add_api(cls, token, body):
        url = "http://ihrm2-test.itheima.net/api/sys/user"
        heaser = {"Content-Type": "application/json", "Authorization": token}

        add_res = requests.post(url=url, headers=heaser, json=body)
        return add_res

    # 查询员工接口
    @classmethod
    def query_api(cls, token, id):
        url = f"http://ihrm2-test.itheima.net/api/sys/user/{id}"
        header = {"Authorization": token}

        query_res = requests.get(url=url, headers=header)
        return query_res

    # 修改员工接口
    @classmethod
    def chang_api(cls, token, id):
        url = f"http://ihrm2-test.itheima.net/api/sys/user/{id}"
        header = {"Content-Type": "application/json", "Authorization": token}

        chang_res = requests.put(url=url, headers=header)
        return chang_res

    # 删除员工接口
    @classmethod
    def del_api(cls, token, id):
        url = f"http://ihrm2-test.itheima.net/api/sys/user/{id}"
        header = {"Authorization": token}

        del_res = requests.delete(url=url, headers=header)
        return del_res

    pass
